package net.wanho.index.controller;
import net.wanho.commons.factory.BeanFactory;
import net.wanho.index.service.IndexService;
import net.wanho.systemSettings.vo.EmployeeVo;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ControlServlet")
public class ControlServlet extends HttpServlet{

	private IndexService indexService = BeanFactory.getBean(IndexService.class) ;
	
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String methodName = request.getParameter("method");
		try {
			Method method = getClass().getDeclaredMethod(methodName,
					HttpServletRequest.class, HttpServletResponse.class);
			method.setAccessible(true);
			method.invoke(this, request, response);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	protected void countAll(HttpServletRequest request,HttpServletResponse response) throws IOException {
		try {
			//1.获得session中 当前登录的员工
			EmployeeVo employeeVo = (EmployeeVo) request.getSession().getAttribute("employeeVo");
			//2. 获得工号
			Integer employeeId = employeeVo.getEmployeeId();
			//3. 查询
			Map<String, Object> map = indexService.countAll(employeeId);
			request.setAttribute("map",map);
			request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
